package org.chatboleh.tools;

import java.awt.Color;
import java.util.List;

import org.chatboleh.bean.TextElement;
import org.chatboleh.bean.User;
import org.chatboleh.exception.EDMException;

public class TextElementFactory extends BaseFactory {
	private static TextElementFactory textfactory = null;

	/**
	 * This returns the singleton instance
	 */
	public static TextElementFactory getInstance() {
		if (textfactory == null) {
			textfactory = new TextElementFactory();
		}
		return (textfactory);
	}

	/**
	 * Create an instance of TextElement and save it into the database. Be
	 * careful if you don't want to create records into the database.
	 * 
	 * @param fontColor
	 * @param fontName
	 * @param fontSize
	 * @param fontStyle
	 * @param text
	 * @param width
	 * @param x
	 * @param y
	 * @return
	 */
	public static TextElement createTextElement(Color fontColor,
			String fontName, int fontSize, int fontStyle, String text,
			int width, int x, int y) {
		TextElement te = new TextElement();
		te.setFontColor(fontColor);
		te.setFontName(fontName);
		te.setFontSize(fontSize);
		te.setFontStyle(fontStyle);
		te.setText(text);
		te.setWidth(width);
		te.setX(x);
		te.setY(y);
		try {
			te.save();
		} catch (EDMException e) {
			logger.error(e);
		}
		return te;
	}

	public List<TextElement> getTextElementList(String criteria) {
		try {
			return new TextElement().getList(criteria);
		} catch (EDMException e) {
			logger.error(e);
		}
		return null;
	}

}
